import { MessageBox,Message } from 'element-ui';
//excel所需依赖
import excelJs from './ExportExcel';
//解析excel数据
const formatJson = function(filterVal, jsonData) {
    return jsonData.map(v => filterVal.map(j => {
        return v[j]
    }))
}
//解析txt数据
const fakeClick = function(obj) {
    const ev = document.createEvent("MouseEvents");
    ev.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    obj.dispatchEvent(ev);
}
const downLoadInfo = {
    /**
     * 导出excel表
     * @param {表格数据} list 
     * @param {表头} tHeader 
     * @param {表内容} tValue 
     * @param {表名} filename 
     */
    exportExcel:function(list,tHeader,tValue,filename){
        if(!list || !tHeader || !tValue){
            return MessageBox.alert('参数传入有误！', '错误', {
                confirmButtonText: '确定',
                type: 'error',
            });
        }
        //如果没有定义文件名就设置默认
        if(!filename && filename==''){
            filename = 'excel'
        }
        // MessageBox.confirm('是否导出为 Excel?', '提示', {
        //     confirmButtonText: '确定',
        //     cancelButtonText: '取消',
        //     type: 'warning',
        //     center: true
        // }).then(() => {
            const data = formatJson(tValue, list);
            let autoWidth = true
            let bookType = 'xlsx'
            excelJs.export_json_to_excel({
                header: tHeader,
                data,
                filename: filename,
                autoWidth: autoWidth,
                bookType: bookType
            })
        // }).catch(() => {});
    },
   
   
}
export default downLoadInfo